/*
 * @Author: liuying 247220246@qq.com
 * @Date: 2024-12-20 17:52:41
 * @LastEditors: liuying 247220246@qq.com
 * @LastEditTime: 2024-12-23 17:49:45
 * @FilePath: \my-book-react\src\hooks\useRequest\axiosInstance.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
const axiosConfig: AxiosRequestConfig = {
  timeout: 5000,
  headers: {
    'Content-Type': 'application/json;charset=utf-8',
  },
  responseType: 'json',
};
const axiosInstance = axios.create(axiosConfig);
axiosInstance.interceptors.response.use(
  (res: AxiosResponse) => {
    if (res.status !== 200 || !res.data) {
      throw 'error';
    }
    return res.data;
  },
  (error: AxiosError) => {
    throw error;
  }
);
export default axiosInstance;
